package cn.dongqihong.produceconsumption;

import java.util.Date;

/**
 * 厨师
 * Created by DongQihong on 2016/12/15.
 */
public class Cook extends Thread {
    private Basket basket;
    private String name;
    boolean flag = true;

    /**
     * 创建厨师
     *
     * @param name   厨师名
     * @param basket 放包子的篮子
     */
    public Cook(String name, Basket basket) {
        this.name = name;
        this.basket = basket;
    }

    @Override
    public void run() {
        while (flag) {
            Bun bun = makeBun();
            basket.in(bun);
        }
    }

    /**
     * 做包子
     *
     * @return 包子
     */
    public Bun makeBun() {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        long id = new Date().getTime();
        return new Bun(id);
    }

    /**
     * 设置篮子
     *
     * @param basket 篮子
     */
    public void setBasket(Basket basket) {
        this.basket = basket;
    }

    /**
     * 停止生产
     */
    public void stopMake() {
        this.flag = false;
    }
}
